<template>
  <j-modal
    :title="'选择算法'"
    :width="'900px'"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="8" :lg="7" :md="8" :sm="24">
              <a-form-item label="算法名称">
                <j-input placeholder="请输入算法名称" v-model="queryParam.formulaName"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          :rowSelection="{
            selectedRowKeys,
            onChange: onSelectChange,
            getCheckboxProps: chargeDetailCheckBox,
            type: 'radio',
          }"
          @change="handleTableChange"
        >
          <span slot="formulaContent" slot-scope="text, record">
            <!-- {{ text.replaceAll('@','')}} -->
            <div
              v-html="
                record.formulaContentHtml.replaceAll(
                  'wise',
                  'span style=\'border: 1px solid #dcdfe6;font-size:14px;margin: 0 6px; padding:2px 5px;\''
                )
              "
            ></div>
          </span>
        </a-table>
      </div>
    </a-card>
  </j-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'UserFormulaSelectList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      /* 排序参数 */
      isorter: {
        column: 'id',
        order: 'desc',
      },
      description: '选择算法',
      // 表头
      columns: [
        {
          title: '算法ID',
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: '算法名称',
          align: 'left',
          dataIndex: 'formulaName',
        },
        {
          title: '内容',
          align: 'left',
          dataIndex: 'formulaContent',
          scopedSlots: { customRender: 'formulaContent' },
        },
      ],
      url: {
        list: '/userFormula/userFormula/list',
      },
      dictOptions: {},
      superFieldList: [],
      visible: false,
      disabledFormulaIds: [], //禁用不能选择的算法id
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    // 控制选项禁用 多个状态这样写
    chargeDetailCheckBox(record) {
      var that = this
      return {
        props: {
          disabled:
            that.disabledFormulaIds &&
            that.disabledFormulaIds.length > 0 &&
            that.disabledFormulaIds.indexOf(record.id) > -1,
        },
      }
    },
    initDictConfig() {},
    show(formulaIds) {
      this.disabledFormulaIds = formulaIds
      this.selectedRowKeys = []
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择算法！')
        return
      }
      this.$emit('ok', this.selectionRows[0])
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>